//
//  HotColumnCell.m
//  礼物go
//
//  Created by dllo on 16/5/22.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "HotColumnCell.h"

#define leftSpace 5
#define iconHeight 20

@implementation HotColumnCell

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
        
    }
    return self;
}

-(void)createSubviews{
    self.bgView = [[UIImageView alloc] initWithFrame:self.contentView.bounds];
    self.bgView.image = [UIImage imageNamed:@"bg_share_large"];
    [self.contentView addSubview:self.bgView];
    
    self.coverImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height / 3 * 2)];
    self.coverImage.backgroundColor = [UIColor purpleColor];
    [self.contentView addSubview:self.coverImage];
    
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(leftSpace, self.coverImage.frame.size.height + 5, self.contentView.frame.size.width - leftSpace * 2, 0)];
   // self.nameLabel.dk_backgroundColorPicker = DKColorPickerWithRGB(0xFFFAFA,0xBEBEBE);
    [self.contentView addSubview:self.nameLabel];
     self.nameLabel.numberOfLines = 2;
    self.nameLabel.lineBreakMode =  NSLineBreakByCharWrapping;
    [self.nameLabel sizeToFit];
    
    
    self.moneyIcon = [[UIImageView alloc] initWithFrame:CGRectMake(leftSpace, self.contentView.frame.size.height - 30, 15, iconHeight)];
    //self.moneyIcon.backgroundColor = [UIColor purpleColor];
    [self.contentView addSubview:self.moneyIcon];
    self.moneyIcon.image = [UIImage imageNamed:@"money"];
    
    self.priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(leftSpace + self.moneyIcon.frame.size.width, self.moneyIcon.frame.origin.y, 50, iconHeight)];
   // self.priceLabel.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:self.priceLabel];
    self.priceLabel.textColor = [UIColor redColor];
    self.priceLabel.font = [UIFont systemFontOfSize:15];
    
    self.heartIcon = [[UIImageView alloc] initWithFrame:CGRectMake(self.contentView.frame.size.width * 0.5 + 20 , self.contentView.frame.size.height - 30, 17, iconHeight)];
   // self.heartIcon.backgroundColor = [UIColor purpleColor];
    [self.contentView addSubview:self.heartIcon];
    self.heartIcon.image = [UIImage imageNamed:@"heart3"];
   
    
    self.favoritesLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.heartIcon.frame.origin.x + self.heartIcon.frame.size.width, self.heartIcon.frame.origin.y, 80, iconHeight)];
    //self.favoritesLabel.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:self.favoritesLabel];
    self.favoritesLabel.font = [UIFont systemFontOfSize:15];
    self.favoritesLabel.textColor = [UIColor grayColor];
    
}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.bgView.frame = self.contentView.bounds;
    //self.coverImage.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height / 3 * 2);
    self.coverImage.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height / 3 * 2);
    
    self.moneyIcon.frame = CGRectMake(leftSpace, self.contentView.frame.size.height - 25, 15, iconHeight);
    self.priceLabel.frame = CGRectMake(leftSpace + self.moneyIcon.frame.size.width, self.moneyIcon.frame.origin.y, 50, iconHeight);
   
    self.heartIcon.frame = CGRectMake(self.contentView.frame.size.width * 0.5 + 20 , self.contentView.frame.size.height - 25, 17, iconHeight);
    
    self.favoritesLabel.frame = CGRectMake(self.heartIcon.frame.origin.x + self.heartIcon.frame.size.width, self.heartIcon.frame.origin.y, 80, iconHeight);
    //self.nameLabel.frame = CGRectMake(5, self.coverImage.frame.size.height + 5, self.contentView.frame.size.width - 10, 0);
//    self.nameLabel.numberOfLines = 2;
//    self.nameLabel.lineBreakMode =  NSLineBreakByCharWrapping;
   // [self.nameLabel sizeToFit];

}

-(void)setHotModel:(HotColumnModel *)hotModel{
    _hotModel = hotModel;
    [self.coverImage sd_setImageWithURL:[NSURL URLWithString:_hotModel.cover_image_url] placeholderImage:[UIImage imageNamed:@"picholder"]];
    self.nameLabel.frame = CGRectMake(5, self.coverImage.frame.size.height + 5, self.contentView.frame.size.width - 10, 0);
    self.nameLabel.text = _hotModel.name;
    [self.nameLabel sizeToFit];
    self.priceLabel.text = _hotModel.price;
    self.favoritesLabel.text = [NSString stringWithFormat:@"%@",_hotModel.favorites_count];
    
}

-(void)setHotDeModel:(HotDetailModel *)hotDeModel{
    _hotDeModel = hotDeModel;
    [self.coverImage sd_setImageWithURL:[NSURL URLWithString:_hotDeModel.cover_image_url] placeholderImage:[UIImage imageNamed:@"picholder"]];
    self.nameLabel.frame = CGRectMake(5, self.coverImage.frame.size.height + 5, self.contentView.frame.size.width - 10, 0);
    self.nameLabel.text = _hotDeModel.name;
    [self.nameLabel sizeToFit];
    self.priceLabel.text = _hotDeModel.price;
    self.favoritesLabel.text = [NSString stringWithFormat:@"%@",_hotDeModel.favorites_count];

}







@end
